package com.appspot.yourvirtualgymtrainer;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;



@SuppressWarnings("serial")
public class BaseServlet extends HttpServlet {

  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
	  throws ServletException, IOException {
	  PrintWriter out = resp.getWriter();
	  HttpSession sess = req.getSession(true);

	  System.out.println(sess.getAttribute("isLogged"));
	try {
		if(!sess.getAttribute("isLogged").equals("no")) {
			resp.setContentType("application/json; charset=utf-8");
			resp.setHeader("Cache-Control", "no-cache");
		} else {
			resp.setContentType("text/plain; charset=utf-8");
			out.println("niezalogowany");
		}
  } catch (NullPointerException e) {
	  sess.setAttribute("isLogged", "no");
	  resp.setContentType("text/plain; charset=utf-8");
	  out.println("niezalogowany");
  }
}
}